<template>
	<div class="sys-header">
		<div class="sys-header-left" @click="toggleCollapsed" :style="{ textAlign: showExpend ? '' : 'center' }">
			<img :src="logoUrl" :title="schoolName" v-if="logoUrl" />
			<div class="oe-info-schoolName" v-else>
				<span>{{ schoolName }}</span>
			</div>
		</div>
		<!-- <div class="text"><span>智慧教育考试平台</span></div> -->
		<div class="sys-header-right">
			<div class="avatar">
				<img :src=" avatarUrl || headImg">
			</div>
			<div class="role">
				<div class="role-info">系统管理员</div>
				<div class="welcome">欢迎您!</div>
			</div>
			<div class="logout" @click="loginOut">
				<a-tooltip placement="bottom">
					<template slot="title">
            退出
					</template>
					<img src="../../../assets/icons/header/icon-exit.png">
				</a-tooltip>
			</div>
		</div>
	</div>
</template>

<script>
export default {
	name: 'infoTop',
	props: {
		showExpend: {
			type: Boolean,
			default: true,
		},
		examShow: {
			type: Boolean,
			default: true,
		},
		majorBatch: {
			type: Boolean,
			default: false,
		},
	},
	data() {
		return {
			collapsed: false,
			headImg: 'https://iconfont.alicdn.com/t/1566197395754.jpg@100h_100w.jpg',
			avatarUrl: '',
			displayName: '',
			logoUrl: localStorage.getItem('logoUrl'),
			schoolName: localStorage.getItem('schoolName'),
			isShowManager: false,
			isShowStudent: false,
			// level: 1,
			// duringTime: '--',
			sortId: localStorage.getItem('sortId') || '',
			sortList: [],
			bacthId: localStorage.getItem('bacthId') || '',
			bacthList: [],
			isHavaMajor: false,
			IsShowTicket: false,
		};
	},
	created() {
		this.getAvatorInfo();
		// this.$bus.$off('getSchoolLogo').$on('getSchoolLogo', (val) => {
		// 	console.log(val);
		// 	this.logoUrl = val;
		// });
	},
	mounted() {
		// this.getManagerInfo();
		// if (this.examShow && this.majorBatch) {
		// 	this.getList();
		// 	this.getBacthList();
		// }
	},
	methods: {
		toggleCollapsed() {
			this.collapsed = !this.collapsed;
			this.$emit('toggleCollapsed', this.collapsed);
		},
		getManagerInfo() {
			this.$http.post('/api/common/LocalStorage/getHeadInfo').then((res) => {
				if (res.code < 0) {
					this.$message.warning(res.msg);
					this.$router.push({
						name: 'login',
						params: {},
					});
				} else {
					// this.level = res.level;
					// this.duringTime = res.endTime;
					// console.log('xuxuxu',res);
					// var rx = /^https?:\/\//i;
					// if (rx.test(res.avatarUrl)) {

					//   this.avatarUrl = res.avatarUrl;
					// } else {
					//   this.avatarUrl = 'https://cdn-zjy.icve.com.cn' + res.avatarUrl;
					// }
					this.displayName = res.displayName;
					localStorage.setItem('file_system_url', res.file_system_url);
					this.isShowManager = res.isShowManager;
					this.isShowStudent = res.isShowStudent;
					this.isHavaMajor = res.isHavaMajor;
				}
			});
		},
		getAvatorInfo() {
			this.$http.post('/api/common/accounts/getManagerInfo').then((res) => {
				if (res.code > 0) {
					var rx = /^https?:\/\//i;
					if (rx.test(res.avatarUrl)) {
						this.avatarUrl = res.avatarUrl;
					} else {
						this.avatarUrl = 'https://cdn-zjy.icve.com.cn' + res.avatarUrl;
					}
				} else {
					this.$message.error(res.msg);
				}
			});
		},
		loginOut() {
			var that = this;
			this.$confirm({
				title: '退出登录',
				content: '点击确认后将退出系统！',
				onOk() {
					// return new Promise((resolve, reject) => {
					//   setTimeout(Math.random() > 0.5 ? resolve : reject, 1000);
					// }).catch(() => console.log('Oops errors!'));
					that.$http.post('/api/portal/loginforour/loginOut').then((res) => {
						if (res.code > 0) {
							that.$message.success(res.msg);
							that.$router.push({
								name: 'login',
								params: {},
							});
						}
					});
				},
				onCancel() {
					that.$message.warning('取消退出！');
				},
			});
		},
		getMajorBatch(type) {
			let name = '';
			if (type == 0) {
				name = 'majorClass';
			} else if (type == 1) {
				name = 'batchList';
			}
			this.$router.push({
				name: name,
			});
		},
		getTea() {
			this.$router.push({ name: 'baseInfo' });
		},
		getStu() {
			this.$router.push({ name: 'majorClass' });
		},
		// 分类列表
		getList() {
			this.$http.post('/api/study/sort/getList').then((res) => {
				if (res.list.length > 0) {
					this.sortList = res.list;
					if (!this.sortId) {
						this.sortId = this.sortList[0].Id;
						localStorage.setItem('sortId', this.sortId);
					}
				} else {
					localStorage.setItem('sortId', '');
				}
			});
		},
		handleChange(value) {
			this.sortId = value;
			localStorage.setItem('sortId', value);
			this.changeChild();
			console.log(this.sortList);
			this.updateTitle(value);
		},
		updateTitle(value) {
			let filter = this.sortList.filter((item) => {
				return item.Id == value;
			});
			console.log(filter[0]);
			localStorage.setItem('sortItem', JSON.stringify(filter[0]));
		},
		// 批次列表
		getBacthList() {
			this.$http
				.post('/api/study/batch/getList', {
					title: '',
					type: 1,
				})
				.then((rst) => {
					if (rst.code > 0) {
						this.bacthList = rst.list;
						if (!this.bacthId) {
							this.bacthId = this.bacthList[0].Id;
							localStorage.setItem('bacthId', this.bacthId);
						}
						this.getTicketStatus();
					} else {
						this.$message.error(rst.msg);
					}
				});
		},
		handleChangeBacth(value) {
			this.bacthId = value;
			localStorage.setItem('bacthId', value);
			this.changeChild();
			this.getTicketStatus();
		},
		getTicketStatus() {
			this.$http
				.post('/api/study/batch/getTicket', {
					batchId: this.bacthId,
				})
				.then((rst) => {
					this.IsShowTicket = rst.isShowTicket;
				});
		},
		changeChild() {
			this.$emit('changeChild', false);
			setTimeout(() => {
				this.$emit('changeChild', true);
			}, 500);
		},
		getTicket() {
			this.$router.push({
				name: 'stuTicket',
			});
		},
	},
};
</script>


<style lang="scss" scoped>
.sys-header {
	width: 100%;
	height: 60px;
	background: #fff;
	display: flex;
	justify-content: space-between;

	.sys-header-left {
		width: 200px;
		cursor: pointer;
		img {
			width: 100%;
			height: 100%;
		}
	}
	.sys-header-right {
		flex: 1;
		display: flex;
		align-items: center;
		justify-content: flex-end;
		padding-right: 20px;

		// .oe-top-help {
		// 	margin-right: 10px;
		// 	color: #333;
		// }
		// .oe-top-help:hover {
		// 	color: #1686f6;
		// }
		// .oe-right-welcome {
		// 	margin: 0px 10px 0 0px;
		// 	color: #040f32;
		// 	font-size: 14px;
		// 	font-weight: 400;
		// 	display: inline-block;
		// 	vertical-align: middle;
		// }
		.avatar {
			width: 40px;
			height: 40px;
			border-radius: 100%;
			vertical-align: middle;
			margin-right: 3px;

			img {
				width: 40px;
				height: 40px;
				border-radius: 100%;
			}
		}

		.role {
			margin: 0 20px 0 10px;
			.role-info {
				font-size: 14px;
				font-family: SourceHanSansCN-Normal, SourceHanSansCN;
				font-weight: 400;
				color: #171725;
			}

			.welcome {
				font-size: 12px;
				font-family: SourceHanSansCN-Normal, SourceHanSansCN;
				font-weight: 400;
				color: #92929d;
			}
		}

		.logout {
			cursor: pointer;
		}
	}
}
</style>